package me.znext.learn.android;

import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.support.v4.widget.DrawerLayout;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import me.znext.learn.android.game2048publish.Game2048;

import static android.content.Context.NOTIFICATION_SERVICE;

class LeftMenu {
  LeftMenu(final Context context, final ListView listView, final DrawerLayout drawerLayout) {
    Resources res = context.getResources();
    final String[] menuItemArray = res.getStringArray(R.array.menu_item_array);
    ArrayAdapter adapter = new ArrayAdapter<>(context, R.layout.left_menu_item, menuItemArray);
    listView.setAdapter(adapter);
    final NotificationManager notificationManager = (NotificationManager) context.getSystemService(NOTIFICATION_SERVICE);
    AdapterView.OnItemClickListener leftMenuClickHandler = new AdapterView.OnItemClickListener() {
      @Override
      public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
        Intent intent = new Intent();
        switch (i) {
          case 0:
            intent.setClass(context, CourseSchedule.class);
            break;
          case 2:
            intent.setClass(context, ProfileActivity.class);
            break;
          case 3:
            intent.setAction(Intent.ACTION_VIEW);
            intent.setType("image/*");
            break;
          case 4:
            intent.setClass(context, Game2048.class);
            break;
          case 5:
            intent.setClass(context, FingersActivity.class);
            break;
          case 6:
            intent.setClass(context, MyNoteActivity.class);
            break;
          case 7:
            Notification  notification = new Notification.Builder(context)
              .setAutoCancel(true)
              .setContentTitle("这是提醒标题")
              .setContentText("提醒内容内容")
              .setSmallIcon(R.drawable.ic_launcher)
              .build();
            notificationManager.notify(0x123, notification);
            return;
          case 8:
            intent.setClass(context, Feedback.class);
            break;
          default:
            Notice.alert(context, "", menuItemArray[i] + "还在开发中");
            return;
        }

        context.startActivity(intent);
        drawerLayout.closeDrawer(listView);
      }
    };
    listView.setOnItemClickListener(leftMenuClickHandler);
  }

  LeftMenu(final Activity activity) {
    ListView leftMenu = (ListView) activity.findViewById(R.id.leftMenuList);
    DrawerLayout leftMenuDrawerLayout = (DrawerLayout) activity.findViewById(R.id.leftMenuDrawerLayout);
    new LeftMenu(activity, leftMenu, leftMenuDrawerLayout);
  }
}
